#include <iostream>
#include <pthread.h>

template<class T>
class Singleton{
  public:
    Singleton(){
      pthread_mutex_init(&lock, NULL);
    }
    static T* GetData(){
      if(pdata == nullptr){
        pthread_mutex_lock(&lock);
        if(pdata == nullptr){
          pdata = new T();
        }
        pthread_mutex_unlock(&lock);
      }
      return pdata;
    }
  private:
    volatile static T* pdata;
    static pthread_mutex_t lock;
};

//template<> volatile int* Singleton<int>::pdata = nullptr;
